<template>
    <div>
    <div class="outmain ba_f formwidth">
        <div class="shuju_title mar_b20">
            <div class="shuju_title_text">
                <span>抖音小程序模板消息</span>
            </div>
        </div>
        <div>
            <el-form ref="form" :model="form" :rules="rules" label-width="180px" class="mar_t20">
                <el-form-item label="下单成功通知ID" prop="payOkTid" :required="true">
                    <el-input v-model="form.payOkTid" placeholder="请输入下单成功通知ID" ></el-input>
                </el-form-item>
                <el-form-item label="订单自提通知ID" prop="takeTid" :required="true">
                  <el-input v-model="form.takeTid" placeholder="请输入订单自提通知ID"></el-input>
                </el-form-item>
                <el-form-item label="订单配送通知ID" prop="deliveryTid" :required="true">
                  <el-input v-model="form.deliveryTid" placeholder="请输入订单配送通知ID"></el-input>
                </el-form-item>
                <el-form-item label="订单退款通知ID" prop="refundResultTid" :required="true">
                  <el-input v-model="form.refundResultTid" placeholder="请输入订单退款通知ID"></el-input>
                </el-form-item>
                <el-form-item label="商家接单通知ID" prop="acceptTid" :required="true">
                  <el-input v-model="form.acceptTid" placeholder="请输入商家接单通知ID"></el-input>
                </el-form-item>
            </el-form>
        </div>
    </div>
        <div class="mar_t20 ba_f pad_20 t_c">
            <el-button type="primary" @click="onSubmit()">保存</el-button>
        </div>
    </div>
</template>
<script>
    import { getConfig, postConfig } from '@/api/setup';
    export default {
        created() {
            this.bus.$emit('loading', true);
            this.init();
        },
        data() {
            return {
                activeName:'1',
                form: {
                    payOkTid: '',
                    takeTid: '',
                    deliveryTid: '',
                    refundResultTid: '',
                    acceptTid: '',
                },
                form2: {
                    name: '',
                },
              rules: {
                payOkTid: [{ required: true, message: '请输入下单成功通知ID', trigger: 'blur' }],
                takeTid: [{ required: true, message: '请输入订单自提通知ID', trigger: 'blur' }],
                acceptTid: [{ required: true, message: '请输入商家接单通知ID', trigger: 'blur' }],
                deliveryTid: [{ required: true, message: '请输入订单配送通知ID', trigger: 'blur' }],
                refundResultTid: [{ required: true, message: '请输入订单退款通知ID', trigger: 'blur' }]
              },
                list: [],
                listLoading: true,
                selectRows: "",
                elementLoadingText: "正在加载...",
            }
        },
        methods: {
            async init() {
              getConfig({ ident: 'toutiaoTemplates' }).then((res) => {
                if (res.code == 1) {
                  Object.assign(this.form, res.data);
                  this.bus.$emit('loading', false)
                }
              });
            },
            async onSubmit() {
                if (this.activeName == '1') {
                    this.$refs["form"].validate(async (valid) => {
                        if (valid) {
                            this.form.ident = 'toutiaoTemplates'
                            this.form.identName = '抖音小程序模板消息'
                            const {msg} = await postConfig(this.form);
                            this.$baseMessage(msg, "success");
                            this.init();
                        } else {
                            return false;
                        }
                    });
                }
            }
        }
    }
</script>
